package com.drone.drone_demo.controller;

import com.drone.drone_demo.service.JsonFileService;
import com.google.gson.JsonArray;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/flight")
public class JsonFileController {
    @Autowired
    private JsonFileService jsonFileService;

    @GetMapping("/file")
    public ResponseEntity<?> getFlightData() {
        Map<String, Object> res = new HashMap<>();
        String filePath = System.getProperty("user.dir") + "/full_flight_data_cleaned.json";
        List<Map<String, Object>> flightDatas = jsonFileService.readFlightDataAsList(filePath);
        if (flightDatas != null) {
            res.put("code", 200);
            res.put("data", flightDatas);
            return ResponseEntity.ok(res);
        }
        return ResponseEntity.badRequest().body("error gets data");
    }
}
